#ifndef THREADSERIALPORT_H
#define THREADSERIALPORT_H

#include <QObject>
#include <QThread>
#include <QSerialPort>

#include "CommonTypes.h"

class ThreadSerialPort : public QObject
{
    Q_OBJECT
public:
    explicit ThreadSerialPort(QObject *parent = nullptr);
    ~ThreadSerialPort();


private:
    QString ByteArrayToHexSpaced(const QByteArray &);

private slots:
    void slotHandlerReadyRead();

public slots:
    void slotOpenSerialPort(SerialPortSettings *);
    void slotCloseSerialPort();
    void slotTransmitData(QByteArray);


private:
    QThread *mThread = nullptr;
    QSerialPort *mSerialPort = nullptr;

    QByteArray recvData;

signals:
    void signalOpenSerialPort(bool, QString);
    void signalCloseSerialPort(bool);
    void signalSerialPortErrorOccurred(QSerialPort::SerialPortError);

    // void signalReceiveReadOnlyRegMsg(quint16, quint16);
    // void signalReceiveReadWriteRegMsg(quint16, quint16);
    void signalReceivedAnswerFrame(QByteArray);


    void signalTransmitData(QString);
    void signalReceivedData(QString);
    void signalTransmitErrorCode(QString);

};

#endif // THREADSERIALPORT_H
